package com.hqyj.project.service.impl;


import com.hqyj.project.dto.TripDto;
import com.hqyj.project.mapper.TripMapper;
import com.hqyj.project.service.TripService;
import com.hqyj.project.utils.CommonResult;
import com.hqyj.project.vo.PageVo;
import com.hqyj.project.vo.TripVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class TripServiceImpl implements TripService {

    @Autowired
    private TripMapper tripMapper;


    @Override
    public CommonResult selectAllTripInfo(TripDto tripDto) {
        List<TripVo> trips = tripMapper.selectAllTripInfo(tripDto);
        Integer totals = tripMapper.selectCount(tripDto);
        PageVo<TripVo> pageVo = new PageVo<>(tripDto.getCurrentPage(), tripDto.getPageSize(), totals, trips);
        return new CommonResult(200,"查询成功",pageVo);
    }

    @Override
    public CommonResult applyToTrip(TripDto tripDto) {
        try {
            tripMapper.applyToTrip(tripDto);
            return new CommonResult(200,"申请已提交");
        } catch (Exception e) {
            return new CommonResult(500,"服务器出错");
        }
    }

    @Override
    public CommonResult permit(String userName) {
        try {
            tripMapper.permit(userName);
            return new CommonResult(200,"操作成功");
        } catch (Exception e) {
            return new CommonResult(500,"服务器错误");
        }
    }

    @Override
    public CommonResult notPermit(String userName) {
        try {
            tripMapper.notPermit(userName);
            return new CommonResult(200,"操作成功");
        } catch (Exception e) {
            return new CommonResult(500,"服务器错误");
        }
    }

    @Override
    public CommonResult selectPersonalTrip(String userName) {
        try {
            List<TripVo> tripVos = tripMapper.selectPersonal(userName);
            return new CommonResult(200,"操作成功",tripVos);
        } catch (Exception e) {
            return new CommonResult(500,"服务器错误");
        }
    }

    @Override
    public CommonResult updateStart(String userName) {
        try {
            tripMapper.updateStart(userName);
            return new CommonResult(200,"辛苦了,出差这么久，快休息休息");
        } catch (Exception e) {
            return new CommonResult(200,"服务器错误");
        }
    }


}
